<?php
/**
 * Created by PhpStorm.
 * User: chenxiang
 * Date: 2017/5/3
 * Time: 15:30
 */

namespace App\Http\Controllers\Home;


use App\Model\Json;
use App\Model\Menu;
use Illuminate\Http\Request;

class MenuController extends CommonController
{

    public function index(){
        $menus = Menu::orderBy('id','desc')->get();
        $allmenu = $menus;
        $menus = Menu::getMenus($menus->toArray());
        return view('Home.Menu.index',compact('menus','allmenu'));
    }


    public function add(Request $request){
        $input = $request->only('name','pid','permission');
        if(is_null($input['permission'])){
            unset($input['permission']);
        }
        return Menu::MenuAdd($input);
    }


    public function edit(Request $request){
        $input = $request->only('id','name','permission','order');
        if(is_null($input['permission'])){
            unset($input['permission']);
        }
        return Menu::Menuset($input);
    }

    public function delete(Request $request){
        $id = $request->input('id');
        return Menu::Menu_Del($id);
    }

}